package moe.util;

public class Paging {
	private int itemTotal, pageSize, pageNumber;

	public Paging() {
		this(1);
	}

	public Paging(int pageSize) {
		this.pageSize = pageSize;
		this.itemTotal = -1;
		this.pageNumber = 1;
	}

	public void setItemTotal(int itemTotal) {
		this.itemTotal = itemTotal;
	}

	public int getItemTotal() {
		return itemTotal;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	/***/
	public int getPagingItemOffset() {
		return (pageNumber - 1) * pageSize;
	}

	public int getPageTotal() {
		int pageTotal = itemTotal / pageSize;
		if (itemTotal % pageSize > 0)
			pageTotal++;
		return pageTotal;
	}

	public boolean hasNext() {
		return pageNumber < getPageTotal();
	}

	public int getNext() {
		if (hasNext())
			return pageNumber + 1;
		else
			return pageNumber;
	}

	public boolean hasPre() {
		return pageNumber > 1;
	}

	public int getPre() {
		if (hasPre())
			return pageNumber - 1;
		else
			return pageNumber;
	}
}
